#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
#include <pwd.h>

void err_sys(char* msg) {
    printf("err_sys %s\n", msg );
    exit(0);
}

static void my_alarm(int signo) {
    // signal(SIGALRM, my_alarm);
    printf("in signal handler\n");
    struct passwd *rootptr;
    if ((rootptr = getpwnam("root")) == NULL)
        err_sys("getpwnam(root) error");
    alarm(1);
}

int main(void) {
    struct passwd *ptr;
    signal(SIGALRM, my_alarm);
    alarm(1);
    for ( ; ; ) {
        if ((ptr = getpwnam("wzq")) == NULL)
            err_sys("getpwnam error");
        if (strcmp(ptr->pw_name, "wzq") != 0)
            printf("return value corrupted!, pw_name = %s\n",
                   ptr->pw_name);
    }
}

// sometimes corrupt
/*
in signal handler
^C
$ ./a.out
in signal handler
^C
$ ./a.out
in signal handler
^C
$ ./a.out
in signal handler
return value corrupted!, pw_name = root
in signal handler
^C


**/



